package itheima.jdk8.stream;


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest10 {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("world","hello", "world", "hello world");

        //maptoint 将每个单词映射成它的长度

//        System.out.println(  list.stream().mapToInt(item -> item.length()).filter(length -> length == 5).
//                findFirst().orElse(0));
       //加了final 之后就把筛选的问题确定了下来流弊了！！
        final  List<String> list2 = list.stream().filter(length -> length.startsWith("w")).collect(Collectors.toList());
        System.out.println(list2);

        list.stream().mapToInt(item -> {
            int length = item.length();
            System.out.println(item);
            return length;
        }).filter(length -> length == 5).findFirst().ifPresent(System.out::println);

    }
}
